package com.ehaoyao.consumer;

import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * <dl>
 * <dt>OrderCustomer</dt>
 * <dd>Description:</dd>
 * <dd>Copyright: Copyright (C) 2006</dd>
 * <dd>CreateDate: 2020/5/12</dd>
 * </dl>
 *
 * @author zhangyp
 */
@Component
public class RakbbitmqConsumer {


    private Logger logger = LoggerFactory.getLogger(getClass());


    @RabbitListener(queues = "zyporderDelayQueue2",concurrency = "2")
    public void process(Object map, Message message, Channel channel) throws IOException {
        try {
            logger.info("开始执行订单ID[{}]的支付超时订单关闭......", map);
            logger.info("开始执行订单金额[{}]的支付超时订单关闭......", map);
            //TODO
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
            logger.info("超时订单处理完毕");
        } catch (Exception e) {
            logger.error("超时订单处理失败:{}", e.getMessage());
            channel.basicReject(message.getMessageProperties().getDeliveryTag(), false);
        }
    }
}
